# auther：wanghao
import time

from case.base.basepage import BasePage
from case.base import route
from case.pages.storepage import StorePage

"""
首页其他页面
"""
class OtherPage(BasePage):

    """
    首页客服页面
    """

    def to_cell_page(self):
        self.mini.page.get_element("view.index--tab-bar-item.index--index-3").click()
        self.mini.page.get_element("view.component-index--menu-2").get_elements("van-cell[is='@vant/weapp/dist/cell/index']")[2].click()

    """
    判断从首页点击我的模块-进入客服页面，判断跳转路径是否正确
    """

    def check_cell_page(self):
        time.sleep(2)
        self.mini.assertEqual(self.current_path(), route.cell_route, "对比客服path出错")

    """
    首页setting页面
    """

    def to_setting_page(self):
        self.mini.page.get_element("view.index--tab-bar-item.index--index-3").click()
        self.mini.page.get_element("view.component-index--menu-2").get_elements("van-cell[is='@vant/weapp/dist/cell/index']")[
            0].click()

    """
    判断从首页点击我的模块-进入setting页面，判断跳转路径是否正确
    """

    def check_setting_page(self):
        time.sleep(1)
        self.mini.assertEqual(self.current_path(), route.setting_route, "对比设置path出错")

    """
    首页address页面
    """

    def to_address_page(self):
        self.mini.page.get_element("view.index--tab-bar-item.index--index-3").click()
        self.mini.page.get_element("view.component-index--menu-1").get_elements("van-cell[is='@vant/weapp/dist/cell/index']")[-1].click()

    """
    判断从首页点击我的模块-进入address页面，判断跳转路径是否正确
    """

    def check_address_page(self):
        time.sleep(0.5)
        self.mini.assertEqual(self.current_path(), route.address_route, "对比地址path出错")

    """
    更新小店昵称后check结果
    """

    def check_modify_nick_name(self):
        time.sleep(1)
        nick_name_element = self.mini.page.get_elements("van-cell[is='@vant/weapp/dist/cell/index']")[1].get_element(
            "view[bind:tap='onClick']").get_elements("view")[1]
        nick_name = nick_name_element.inner_text
        nick_name_element.click()
        # 修改的名称
        input_value = nick_name + str(int(time.time() / 10000))
        self.modify_nick_name(input_value)
        # 恢复的名称
        nick_name_element.click()
        self.modify_nick_name(nick_name)

    """
    更新小店昵称
    """

    def modify_nick_name(self, input_nick_name):
        # 输入内容
        input_element = self.mini.page.get_element("input.van-field__control.field-index--van-field__control")
        input_element.input(input_nick_name)
        input_element.trigger("confirm", {"value": input_nick_name})
        # 确认修改
        self.mini.page.get_element(
            "button.confirm-button.van-button.button-index--van-button.van-button--default.van-button--normal.van-button--block").click()
        # 对比修改后的名称
        time.sleep(2)
        modify_nick_name = self.mini.page.get_elements("van-cell[is='@vant/weapp/dist/cell/index']")[1].get_element(
            "view[bind:tap='onClick']").get_elements("view")[1].inner_text
        self.mini.assertEqual(modify_nick_name, input_nick_name, "修改nickname失败")
